<?php 
	require_once 'util/public.php';
	session_start();
	$islogin = FALSE;
	if(isset($_SESSION['login_user'])){
		$islogin = TRUE;
}?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图片展示</title>

<link rel="stylesheet" href="./style/default.css" type="text/css" />
<link rel="stylesheet" href="./style/post.css" type="text/css" />
<script type="text/javascript" src="js/jquery-1.4.4.js"></script> 
<script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script>
<link rel="stylesheet" href="style/jquery.lightbox-0.5.css" type="text/css" media="screen" />

<script type="text/javascript">
    $(function() {
        $('#gallery a').lightBox();
    });
</script>

<style type="text/css" >
/* jQuery lightBox plugin - Gallery style */
#gallery {
	margin-left: 15px;
	padding: 0 20px;
}

#gallery ul {
	list-style: none;
}

#gallery ul li {
	display: inline;
}

#gallery ul img {
	margin: 5px 5px 20px;
	padding: 5px 8px 20px;
	border: none;
}

#gallery ul a:hover img {
	margin: 5px 5px 20px;
	padding: 5px 8px 20px;
	background: #00ee00;
	color: #fff;
}

#gallery ul a:hover {
	color: #fff;
}

.g_group{
	border-radius: 7px;
	border: 1px solid #D3E2fA;
	margin-top: 20px;
	margin-bottom; 2px;
}
.gtitle{
	font-size: 16px;
	font-weight: bold;
	border-bottom: 3px solid #D3E2fA
}


</style>


<?php
/**
 * 输出图片到页面
 * Enter description here ...
 * @param string $path 
 *    路径
 * @return 返回读取的图片的个数
 */
function echo_imgs($path) {
	// 遍历gallery目录输出
	/**
	 * 标准图像的格式为image_x_text_.jpg， x为数字， text 为描述文字
	 * 缩略图的文件名格式为thumb_image_1_.jpg
	 * 所以在区分的时候将数字explode为数组
	 */
	echo '<div id="gallery">';
	echo "<ul>";
	if ($handle = opendir ( $path )) {
		$filecount = 0;
		while ( false !== ($file = readdir ( $handle )) ) {
			$file = iconv ( "gbk", "utf-8", $file );
			if ($file !== "." && $file != "..") {
				$filecount ++;
				// 分开标准图与预览图
				$file_arr = explode ( "_", $file );
				// 是标准图
				if (count ( $file_arr ) == 4) {
					$index = $file_arr [1];
					$nor_imgs [$index] = $file;
					$img_text [$index] = $file_arr [2];
				} else {
					// 缩略图
					$index2 = $file_arr [1];
					$pre_imgs [$index2] = $file;
				}
			}
		}
		// 输出这些文件名
		$img_count = $filecount / 2;
		for($i = 1; $i <= $filecount / 2; $i ++) {
			echo "<li>";
			echo '<a href="images/gallery/' . $nor_imgs [$i] . '" title="' . $img_text [$i] . '">';
			echo '<img src="images/gallery/' . $pre_imgs [$i] . '" width="72" height="72" alt="" />';
			echo '</a>';
			echo "</li>";
		}
	} else {
		echo "<li>还没有添加图片</li>";
	}
	echo "</ul>";
	echo "</div>";
	
	return $img_count;
}
?>

</head>
<body>
	<div id="page_header">
	</div>
	<div id="nav_line">
	<ul id="nav_list">
		<li><a href="index.php">网站首页</a></li>
		<li><a href="intro.php">公司介绍</a></li>
		<li class="active"><a href="pic_show.php">图片展示</a></li>
		<li><a href="knowledge.php">花卉知识</a></li>
		<li><a href="contact.php"">业务联系</a></li>
		<li><a href="feedback.php">客户留言</a></li>
	</ul>
	</div>
	
	<div class="body_content">
		<div class="intro_content">
  			<div class="left">
  				<h1>展示列表</h1>
  				（共3项展示）
  				<ul>
  					<li><a href="pic_show.php?id=1">花卉中心展示</a></li>
  					<li><a href="pic_show.php?id=2">花卉展示</a></li>
  					<li><a href="pic_show.php?id=3">其他展示</a></li>
  				</ul>
  			</div>
  			<div class="right">
  				<?php 
  				$request_id = $_GET['id'];
  				if( !isset($request_id) ){
  					$request_id = 1;
  				}
  				if( $request_id == 1 ){
  					echo '<h1>中心展示</h1>';
  					echo '<p class="p_little"></p>';
  					$cou = echo_imgs( "images/gallery" );
  					echo '<p class="p_little">共: '.floor($cou)." 张图片</p>";
  				}else if( $request_id == 2 ){
  					echo '<h1 >花卉展示</h1>';
  					echo '<p class="p_little"></p>';
  					$cou = echo_imgs( "images/gallery" ); 
  					echo '<p class="p_little">共: '.floor($cou)." 张图片</p>";
  				}else{
  					echo '<h1 >其他展示</h1>';
  					echo '<p class="p_little"></p>';
  					$cou = echo_imgs( "images/gallery" );
  					echo '<p class="p_little">共: '.floor($cou)." 张图片</p>";
  				}
			  	?>
  			</div>
  		</div>
	</div>
	
	 <?php echo_footer($islogin)
  ?>
</body>

</html>
